<#import "../tpl/pageTep.ftl" as page>

    <@page.pageBase currentMenu="店铺管理">
<style>
  .form-horizontal .controls {
    line-height: 40px;
    height: 40px;
    margin-left: 3px;
  }

  .button-primary {
    margin-left: -10px;
  }
</style>
    <!--suppress ALL -->
    <form id="searchForm" class="form-panel"  action="${basepath}/rest/manage/store/selectStorePage">
        <ul class="panel-content">
            <li>
                <div class="form-actions">
                    <div class="control-group span5">
                        <div class="search-controls  controls">
                            <input type="text" name="name" id="name" value="" placeholder="搜索关键字">
                        </div>
                    </div>
                    <div class="form-actions span2">
                        <button type="submit" class="button  button-primary">
                            搜索
                        </button>
                    </div>
                    <a href="${basepath}/rest/manage/store/toAdd" class="button button-success">新增
                    </a>
                    <a  class="button button-danger" href="javascript:delFunction()">
                        批量删除
                    </a>
                </div>
            </li>
        </ul>
    </form>
    <div id="grid"></div>
<script>
var Grid = BUI.Grid,
        Store = BUI.Data.Store,
        columns = [
            {title: '序号', dataIndex: 'id', elCls: 'center', width: '5%'},
            {title : '店铺名称',dataIndex :'name', elCls: 'center', width: '10%'},
            {title : '店铺地址',dataIndex :'address' , elCls: 'center', width: '10%'},
            {title : '店铺公告',dataIndex :'notice', elCls: 'center', width: '10%'},
            {title : '纬度',dataIndex :'lng', elCls: 'center', width: '6%'},
            {title : '经度',dataIndex :'lat', elCls: 'center', width: '6%'},
            {title : '联系电话',dataIndex :'phone', elCls: 'center', width: '8%'},
            {title : '股东位数',dataIndex :'partnerAmount', elCls: 'center', width: '5%'},
            {title : '店铺头像',dataIndex :'icon', elCls: 'center', width: '15%', renderer: function (value) {
                return '<img src="/' + value + '" style="width:110px;height:110px" />';
            }
            },
            {title : '店铺背景图',dataIndex :'background', elCls: 'center', width: '15%', renderer: function (value) {
                return '<img src="/' + value + '" style="width:110px;height:110px"/>';
            }
            },
            {title : '桌位二维码',dataIndex :'id', elCls: 'center', width: '5%', renderer: function (value) {
                return '<a href="${basepath}/rest/manage/seat/toList?id=' + value + '">查看</a>';
            }
            },
            {title: '操作', dataIndex: 'id', elCls: 'center', width: '10%', renderer: function (value, data) {
                var option1 = '<a href="${basepath}/rest/manage/store/toEdit?id=' + value + '">编辑</a>';
                var option2 = '<a href="javascript:deleteOne(' + value + ')">删除</a>';
                return option1 + "&nbsp;&nbsp;&nbsp;&nbsp;" + option2;
            }
            }
        ];

  //分页查询
var store = new Store({
            url : '/rest/manage/store/selectStorePage',
            autoLoad:true, //自动加载数据
            params : { //配置初始请求的参数
                length : '10',
            },
            pageSize:10,	// 配置分页数目
            root : 'list',
            totalProperty : 'total'
        }),
  grid = new Grid.Grid({
            render:'#grid',
            columns : columns,
            loadMask: true, //加载数据时显示屏蔽层
            store: store,
            plugins : [Grid.Plugins.CheckSelection], // 插件形式引入多选表格
            // 底部工具栏
            bbar:{
                pagingBar:true
            }
        });

grid.render();
/*--------------------------------模糊查询---------------------------------------------*/
var form = new BUI.Form.HForm({
    srcNode: '#searchForm'
}).render();

form.on('beforesubmit', function (ev) {
    //序列化成对象
    var obj = form.serializeToObject();
    obj.start = 0; //返回第一页
    store.load(obj);
    return false;
});
/*--------------------------------模糊查询---------------------------------------------*/
/*--------------------------------删除用户---------------------------------------------*/
//删除选中的记录
function delFunction() {
    BUI.Message.Confirm('确认要删除吗？', function () {
        var selections = grid.getSelection();
        var ids = new Array();
        for (var i = 0; i < selections.length; i++) {
            ids[i] = selections[i].id.toString()
        }
        $.ajax({
            type: "POST",
            url: "${basepath}/rest/manage/store/deletesJson",
            dataType: "json",
            data: {
                ids: ids
            },
            success: function (data) {
                var obj = new Object();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });
    }, 'question');
}
//删除单个用户
function deleteOne(value) {
    BUI.Message.Confirm('确认要删除吗？', function () {
        $.ajax({
            type: 'POST',
            url: '${basepath}/rest/manage/store/deleteJson',
            dataType: 'json',
            data: {
                id: value
            },
            success: function () {
                var obj = form.serializeToObject();
                obj.start = 0; //返回第一页
                store.load(obj);
            }
        });
    }, 'question');
}
/*--------------------------------删除用户---------------------------------------------*/
</script>

</@page.pageBase>
